package com.hczt.xhminiapp.adminapi.modules.system.controller;


import com.hczt.xhminiapp.adminapi.modules.system.service.SysPermissionService;
import com.hczt.xhminiapp.common.bean.RtnResult;
import com.hczt.xhminiapp.db.entity.SysPermission;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 红创-马海强
 * @date 2019-03-13 13:55
 * @description 系统菜单管理
 */
@RestController
@RequestMapping("/sys/permissions")
public class SysPermissionController {
    
    @Resource
    private SysPermissionService sysPermissionService;
    
    /**
     * 系统菜单树
     * @return
     */
    @GetMapping("/tree")
    public Object tree(){
        List<SysPermission> tree = sysPermissionService.findSysMenuTree();
        return RtnResult.success(tree);
    }

    /**
     * 系统菜单详情
     * @return
     */
    @GetMapping("/detail")
    public Object detail(@RequestParam String permissionId){
        SysPermission sysMenu = sysPermissionService.findSysMenuDetail(permissionId);
        return RtnResult.success(sysMenu);
    }

    /**
     * 系统菜单添加
     * @param sysPermission
     * @return
     */
    @PostMapping("/add")
    public Object add(@RequestBody SysPermission sysPermission){
        sysPermissionService.update(sysPermission);
        return RtnResult.success();
    }

    /**
     * 系统菜单修改
     * @param sysPermission
     * @return
     */
    @PostMapping("/edit")
    public Object edit(@RequestBody SysPermission sysPermission){
        sysPermissionService.update(sysPermission);
        return RtnResult.success();
    }

    /**
     * 系统菜单删除
     * @param sysPermission
     * @return
     */
    @PostMapping("/remove")
    public Object remove(@RequestBody SysPermission sysPermission){
        sysPermissionService.remove(sysPermission.getPermissionId());
        return RtnResult.success();
    }
}
